### 配置mamba+jupyter+julia+R的基础语言环境
###
 # @Author       : yf_Ming && yf_Ming@csu.edu.cn
 # @Date         : 2023-09-14 14:41:18
 # @LastEditors  : hn3ng4n@163.com hn3ng4n@qq.com
 # @LastEditTime : 2023-09-17 02:19:50
 # @FilePath     : \Code\base_env.sh
 # Copyright (c) 2023, All Rights Reserved.
###

########################### base ############################
#判断当前环境是windows还是linux，并下载wget,mamba|conda基础包, 更新模式
uname_s=$(uname -s)
if [ "$uname_s" = "Linux" ] || [ "$uname_s" = "Darwin" ]; then
    echo "Current environment is Linux"
    curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
    sh Mambaforge-$(uname)-$(uname -m).sh -b -u
    source ./mambaforge/bin/activate
    mamba init
else
    echo "Current environment is Windows"
    winget install mambaforge || echo "Failed to install mambaforge, please install it manually"
    mamba activate || echo "Please add the path environment variable and then run the script again"
    mamba init
fi

# # 配置镜像
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

# # 安装项目环境管理工具
# https://pypa.github.io/pipx/troubleshooting/
pip install pipx -U
pipx ensurepath
pipx install pdm pipx --force

# # 配置pdm环境
pdm config pypi.url https://pypi.tuna.tsinghua.edu.cn/simple
pdm config venv.with_pip True
pdm config install.cache on

# # 安装基础开发框架
mamba install jupyterlab nb_conda_kernels r-essentials nodejs git -y

# #######################################################################
# # 用pdm配置好环境后，就不用先激活哪个环境，而是可以直接用，pdm run了

echo "finish install base dev env!"
